package cn.szq.concurrent.thread;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;

/**
 * @ClassName: HashMapNotSafe
 * @Description:
 * @Author: szq
 * @Date: 2021-10-08 15:41:19
 */
public class HashMapNotSafe {

    public static void main(String[] args) {
        final Map<Integer, String> map = new HashMap<>();

        final Integer targetKey = 0b1111_1111_1111_1111;
        final String targetValue = "V";
        map.put(targetKey, targetValue);

        new Thread(()->{
            IntStream.range(0, targetKey).forEach(key->map.put(key, "someValue"));
        }).start();

        while (true){
            if (null == map.get(targetKey)){
                throw new RuntimeException("HashMap is not thread safe");
            }
        }
    }
}
